//
//  WLTextField+.swift
//  HengYouCai
//
//  Created by wll on 2017/12/27.
//  Copyright © 2017年 lwj. All rights reserved.
//  UITextField+

import Foundation

extension UITextField {
    
    ///清除按钮 可能为空
    var clearBtn: UIButton? {
        get{
            return self.value(forKey: "_clearButton") as? UIButton
        }
    }
    ///占位文字颜色
    var placeHolderColor: UIColor? {
        set{
            // 提前设置占位文字, 目的 : 让它提前创建placeholderLabel
            let oldPlaceholder = self.placeholder;
            self.placeholder = " ";
            self.placeholder = oldPlaceholder;
            
            // 恢复到默认的占位文字颜色
            var tColor = newValue
            if (tColor == nil) {
                tColor = UIColor(red: 0, green: 0, blue: 0.0980392, alpha: 0.22)

            }
            // 设置占位文字颜色
            self.setValue(tColor, forKeyPath: "placeholderLabel.textColor")
        }get{
            return self.value(forKeyPath: "placeholderLabel.textColor") as? UIColor
        }
    }
    
}
